using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class ItemGroupGenerator {
	
	public ItemGroupGenerator(ItemGenerator[]_items){
		items=_items;
	}	

	ItemGenerator[] items;

	public void Generate(Vector2 position) {
		ItemPickup[] generatedItems = new ItemPickup[items.Length];
		int generatedCount = 0;
		foreach(ItemGenerator item in items) {
			ItemPickup generatedItem = null;
			for(int i = 0;i<100;i++) {
				Vector2 offset = Random.insideUnitCircle;
				if(Physics2D.OverlapArea(position+offset-new Vector2(0.3f,0.3f),position+offset+new Vector2(0.3f,0.3f),LayerMask.GetMask("Wall"))==null) {
					generatedItem=item.Generate(position+offset);
					break;
				}
			}

			if(generatedItem!=null) {
				generatedItems[generatedCount]=generatedItem;
				generatedCount++;
			}
		}

		System.Array.Resize(ref generatedItems,generatedCount);
		ItemPickup.BindGroup(generatedItems);
	}
}